//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package 力扣.题库.二分查找;

public class demo_744 {
    public demo_744() {
    }

    public static void main(String[] args) {
        char[] letters = new char[]{'c', 'f', 'g'};
        System.out.println(nextGreatestLetter(letters, 'd'));
    }

    public static char nextGreatestLetter(char[] letters, char target) {
        if (letters[letters.length - 1] < target) {
            return letters[0];
        } else {
            int l = 0;
            int r = letters.length - 1;

            int mid;
            for(mid = l + (r - l) / 2; l < r; mid = l + (r - l) / 2) {
                if (letters[mid] <= target) {
                    l = mid + 1;
                } else if (letters[mid] > target) {
                    r = mid - 1;
                }
            }

            return letters[mid];
        }
    }
}
